﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using KaKaSongGame.ViewModel;

namespace KaKaSongGame
{
    public partial class GameDashboard : UserControl
    {
        public GameDashboard()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(GameDashboard_Loaded);
        }

        void GameDashboard_Loaded(object sender, RoutedEventArgs e)
        {
            // copy
            var vm = this.DataContext as MainPageViewModel;
            var players = new PlayerViewModel[vm.PlayerList.Count];
            vm.PlayerList.CopyTo(players, 0);

            // sort
            var playerlist = players.ToList();
            playerlist.Sort(
                 new Comparison<PlayerViewModel>((a, b) =>
                     {
                         return b.GamePlayer.Score.CompareTo(a.GamePlayer.Score);
                     }));

            LayoutRoot.DataContext = playerlist;
        }
    }
}
